<?php
/**
 * Created by PhpStorm.
 * User: YAN
 * Date: 2017/7/18
 * Time: 15:29
 */

namespace App\Http\Controllers\API;


use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CalendarController extends Controller
{
    public function index(Request $request){
        $res=[];
        $student_id = $request->get('student_id');
        $courses= \DB::table('courses')->join('course_times',function($join){
            $join->on('courses.id','=','course_times.c_id');
        })->join('student_courses',function($join){
                $join->on('student_courses.c_id','=','courses.id');
            })->where(['student_courses.s_id'=>$student_id])->orderBy('course_times.date')->orderBy('course_times.lessons')
            ->get();
        foreach ($courses as $items){
            $item['date']=date('Y/m/d',$items->date);
            $item['title']=$items->c_name;
            $item['desc']=
                "第".$items->lessons."节\n".
                "上课地点：".$items->place."\n".
                "主讲教师：".$items->teacher."\n";
//                "课程号：".$items->c_number."。\n".
//
//                "课序号：".$items->serial_number."__".$items->days."__".$items->weeks."。";
            $res[]=$item;
        }
        return $res;
    }
}